const fileTypeMock = [
  {value:'png',label:'data:image/png'},
  {value:'pdf',label:'data:application/pdf'},
  {value:'jpeg',label:''},
  {value:'jpg',label:''},
  {value:'xls',label:'data:application/vnd.ms-excel'},
  {value:'xlsx',label:'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'},
  {value:'docx',label:'data:application/vnd.openxmlformats-officedocument.wordprocessingml.document'},
  {value:'doc',label:'data:application/msword'},
  {value:'mp4',label:''},
]
const formRules = {
					title: { required: true, message: '请输入标题',trigger: 'blur'},
					author: { required: true, message: '请输入作者',trigger: 'blur'},
					categoryId: { required: true, message: '请选择栏目',trigger: 'blur'},
					coverImage: { required: false, message: '请上传图片',trigger: 'blur'},
					commentTimeAll: { required: true, message: '请选择评论时间',trigger: 'blur'},
					publishTime: { required: true, message: '请选择发布时间',trigger: 'blur'},
					content: { required: true, message: '请输入内容',trigger: 'blur'},
				}
//将base64转换为blob
  function dataURLtoBlob(dataurl) {
    let arr = dataurl.split(','),
        mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]),
        n = bstr.length,
        u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: mime });
}
//将blob转换为file
  function blobToFile(theBlob, fileName, dataId){
   theBlob.lastModifiedDate = new Date();
   theBlob.name = fileName;
   theBlob.dataId = dataId
   return theBlob;
}

function _fileNmae(name,type){
  let arr = name.split('.')
  let arrStr = ''
  arr.forEach((item,index)=>{
      if(arrStr){
        if(index == arr.length-1) arrStr = `${arrStr}.${type}`
        else arrStr = `${arrStr}.${item}`
      }else{
        arrStr = item
      }
  })
  return arrStr
}

export {
  dataURLtoBlob,
  blobToFile,
  _fileNmae,
  formRules
}
